namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class OptionFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Option>()
                .DerivesFrom<Element>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IOption>()
                .Implements<IAttributeDisabled>()
                .Implements<IXmlSerializable>()
                .XmlRoot("option")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Option expected = new Option
            {
                Id = "id",
                Class = "class",
                Disabled = true,
                Label = "label",
                Language = "fr",
                Selected = true,
                Text = "text",
                Title = "title",
                Value = "value"
            };

            string xml = "<option id='id' class='class' lang='fr' title='title' label='label' value='value' disabled='disabled' selected='selected'>text</option>";
            Option actual = xml.Deserialize<Option>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<option />".Deserialize<Option>());
        }

        [Fact]
        public void serialize()
        {
            Option obj = new Option
            {
                Id = "id",
                Class = "class",
                Disabled = true,
                Label = "label",
                Language = "fr",
                Selected = true,
                Text = "text",
                Title = "title",
                Value = "value"
            };

            string xpath = "1=count(/option[@id='id'][@class='class'][@lang='fr'][@title='title'][@label='label'][@value='value'][@disabled='disabled'][@selected='selected'][text()='text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Option());
        }

        [Fact]
        public void ctor_string_string()
        {
            Option obj = new Option("value", "title", "text");

            Assert.Equal<string>("text", obj.Text);
            Assert.Equal<string>("title", obj.Title);
            Assert.Equal<string>("value", obj.Value);
        }

        [Fact]
        public void prop_Disabled()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Disabled"))
                .IsAutoProperty<bool>()
                .Result);
        }

        [Fact]
        public void prop_Label()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Label"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Selected()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Selected"))
                .IsAutoProperty<bool>()
                .Result);
        }

        [Fact]
        public void prop_Text()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Text"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Title()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Title"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Value()
        {
            Assert.True(new PropertyExpectations(typeof(Option).GetProperty("Value"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Option expected = new Option
            {
                Id = "id",
                Class = "class",
                Disabled = true,
                Label = "label",
                Language = "fr",
                Selected = true,
                Text = "text",
                Title = "title",
                Value = "value"
            };

            string xml = "<option id='id' class='class' lang='fr' title='title' label='label' value='value' disabled='disabled' selected='selected'>text</option>";
            Option actual = new Option().Deserialize("option", null, xml) as Option;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}